package stock.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import stock.utils.Result;

@RestController()
@RequestMapping("nacos")
@RefreshScope//自动监听配置更新
@Slf4j
public class NacosConfigController {

    @Value("${spring.cloud.nacos.username}")
    private String username;

//    @NacosValue(value = "${spring.cloud.nacos.discovery.namespace}")//使用springboot的nacos配置可以用这个注解
    @Value("${spring.cloud.nacos.discovery.namespace}")
    private String namespace;

//    @NacosValue(value = "${spring.cloud.nacos.discovery.namespace}",autoRefreshed = true)//使用springboot的nacos配置可以用这个注解
    @Value(value = "${cloud.stock.port}")
    private String testUsername;

    @Value("${timeout}")
    private Integer timeout;//共享配置参数

    @Value("${abc}")
    private String extension;//

    public NacosConfigController() {
    }

    @GetMapping("/get/config")
    public Result getConfig(){
        log.info("Nacos注解获取yml参数："+namespace);
        log.info("Nacos注解获取配置中心监听变化的参数："+testUsername);

        return Result.success(testUsername+"---shared:"+timeout+"---extionsion:"+extension);

    }
}
